home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 2.7 KB | 84 lines | [TEXT/ttxt] |
- --<<<-
- -- Filename:
- -- textprin.sx
-
- -- Purpose:
- -- Defines a method printText on TextPresenter that prints it to
- -- multiple pages of a Printer.
- method printText self {class TextPresenter} margin units -> (
- local p, oldX, oldY, oldBoundary
-
- -- Create a new Printer and set its margins
- p := new PrinterSpace
- setMargin p margin units
-
- -- Record the old dimensions and location and attach the TextPresenter to the printer
- oldBoundary := self.boundary
- self.boundary := p.boundary
- oldX := self.x; oldY := self.y
- self.x := self.y := 0
- append p self
- recalcRegion p
-
- -- Set the context to be the PrinterSurface. The TextPresenter might be queried for
- -- metric information before it's told to draw.
- setContext self p.surface p.globalBoundary
-
- if (printerDialog p) do (
- local firstPage, lastPage, \
- newOffset, pageNum
- local defaultPageHeight := self.height
-
- -- Record the page range.
- -- By setting these back to default values, we indicate that
- -- we will deal with them ourselves.
- firstPage := p.firstPage
- p.firstPage := 1
- lastPage := p.lastPage
- p.lastPage := @all
-
- self.offset := newOffset := 0
- pageNum := 1
-
- -- While there's still text to be printed out
- repeat while (newOffset < self.target.size) do (
-
- self.offset := newOffset
-
- -- Get the offset of the last visibly complete character on this page
- -- The text for the new page will start right after it.
- newOffset := (getLastVisibleOffset self)
-
- -- Get the position of this character and change the height of the presenter
- -- to match that. Note that the point information is returned in global coordinates
- local lastXY := getPointForOffset self newOffset
- self.height := (lastXY.y - self.globalboundary.bbox.y1)/self.globaltransform.d
-
- -- If the current page is within the correct
- -- range, then print it
- if ((pageNum >= firstPage) and \
- ((lastPage = @all) or (pageNum <= lastPage))) do (
-
- -- Take a snapshot of the current page
- printFrame p
-
- -- Flush the current page and move on to a new one
- flushPage p
- )
-
- pageNum := pageNum + 1
- newOffset := newOffset + 1
- -- Restore to standard height
- self.height := defaultPageHeight
- )
-
- flushDocument p
- )
-
- emptyout p
- self.offset := 0
- self.x := oldX; self.y := oldY
- self.boundary := oldBoundary
- )
- -->>>
-